package com.cy.dbsys.controller;

import com.cy.commom.pojo.JsonResult;
import com.cy.dbsys.pojo.SysRole;
import com.cy.dbsys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    /**(用户添加模块)查询角色id,name*/
    @RequestMapping("/doFindRoles")
    public JsonResult doFindRoles() {
        return new JsonResult(sysRoleService.findObjects());
    }

    /**(修改模块)1、基于id查询角色数据*/
    @RequestMapping("/doFindObjectById")
    public JsonResult doFindById(Integer id){
        return new JsonResult(sysRoleService.findById(id));
    }
    /**(修改模块)2、基于id修改自身信息*/
    @RequestMapping("/doUpdateObject")
    public JsonResult doUpdateObject(SysRole entity, Integer[] menuIds) {
        sysRoleService.updateObject(entity, menuIds);
        return new JsonResult("update ok");
    }

    /**(添加模块)添加自身数据*/
    @RequestMapping("/doSaveObject")
    public JsonResult doSaveObject(
            SysRole entity, Integer[] menuIds){
        sysRoleService.saveObject(entity,menuIds);
        return new JsonResult("save ok");
    }

    /**(删除模块)根据id删除角色信息*/
    @RequestMapping("/doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        sysRoleService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    /**(查询模块)查询记录*/
    @RequestMapping("/doFindPageObjects")
    public JsonResult doFindPageObjects(String name,Integer pageCurrent){
        return new JsonResult(sysRoleService.findPageObjects(name,pageCurrent));
    }
}
